package com.ruoyi.quartz.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.quartz.domain.BaseProduct;
import com.ruoyi.quartz.domain.BaseType;
import com.ruoyi.quartz.service.IBaseProductService;
import com.ruoyi.quartz.service.IBaseTypeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/base/product")
public class BaseProductController extends BaseController {

    @Resource
    private IBaseProductService iBaseProductService;

    @GetMapping("/list")
    public TableDataInfo list(BaseProduct baseProduct)
    {
        startPage();
        List<BaseProduct> list = iBaseProductService.selectAll(baseProduct);
        return getDataTable(list);
    }

    @PostMapping
    public AjaxResult add(@RequestBody BaseProduct baseProduct) {
        return toAjax(iBaseProductService.addProduct(baseProduct));
    }

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Integer id)
    {
        return success(iBaseProductService.selectProductById(id));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody BaseProduct baseProduct){
        return toAjax(iBaseProductService.updateProduct(baseProduct));
    }

    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids){
        iBaseProductService.deleteProductByIds(ids);
        return success();
    }

}
